import { BaseHttpService } from "../../shared/services/baseHttp.service";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs/Observable";
import { HttpParams } from "@angular/common/http";
import { HttpClient } from "@angular/common/http";
import { AccountPermissionModel } from "./models/accountPermission.model";

export enum PermissionTypeEnum {
    ResearchProduct = 0,
    Features = 1
}

@Injectable()
export class AccountService extends BaseHttpService {
    constructor(public http: HttpClient) {
        super();
    }

    public getProductPermission(accountId: string, productName: string): Observable<AccountPermissionModel[]> {
        let params: HttpParams = new HttpParams();
        params = params.set("productName", productName);
        return this.http.get<AccountPermissionModel[]>(this.serverUrl + 'accountsserv/api/v1/account/' + accountId + '/productPermission', { params: params });
    }

    public getAccountPermissions(accountId: string, type: PermissionTypeEnum): Observable<any> {
        let params: HttpParams = new HttpParams();
        params = params.set("type", type.toString())
            .set('isActive', true.toString());
        return this.http.get<any>(this.serverUrl + 'accountsserv/api/v1/account/' + accountId + '/accountPermission', { params: params });
    }
}